﻿using LD.Host;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json.Linq;
using System;

namespace LD.Tool
{
    public partial class ToolMesSharpFrm : FrmToolBaseSkip
    {
        public ToolMesSharpFrm()
        {
            InitializeComponent();
            this.btn_ok.Click += Btn_ok_Click;
            this.Shown += FrmTaskTool_Shown;
        }

        private void FrmTaskTool_Shown(object sender, EventArgs e)
        {
            Init();
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            JObject obj = new JObject(); ;
            obj.Add("barcode", this.cob_dataSource.Text);


            this.TB_Tool.Param = obj.ToString();
            this.Close();
        }
        private void Init()
        {
            LoadCache();

            if (this.TB_Tool.Param == null)
                return;

            JObject obj = JObject.Parse(this.TB_Tool.Param);

            this.cob_dataSource.Text = obj["barcode"].ToString();
        }
        private void LoadCache()
        {
            foreach (var item in Cache.Var)
            {
                this.cob_dataSource.Items.Add(item.Name);
            }
        }
    }
}
